Artificial Intelligence Nanodegree

Computer Vision Capstone

Project: Facial Keypoint Detection


Welcome to the final Computer Vision project in the Artificial Intelligence Nanodegree program!

In this project, you’ll combine your knowledge of computer vision techniques and deep learning to build and end-to-end facial keypoint recognition system! Facial keypoints include points around the eyes, nose, and mouth on any face and are used in many applications, from facial tracking to emotion recognition.

There are three main parts to this project:

Part 1 : Investigating OpenCV, pre-processing, and face detection

Part 2 : Training a Convolutional Neural Network (CNN) to detect facial keypoints

Part 3 : Putting parts 1 and 2 together to identify facial keypoints on any image!


*Here's what you need to know to complete the project:

  1. In this notebook, some template code has already been provided for you, and you will need to implement additional functionality to successfully complete this project. You will not need to modify the included code beyond what is requested.

    a. Sections that begin with '(IMPLEMENTATION)' in the header indicate that the following block of code will require additional functionality which you must provide. Instructions will be provided for each section, and the specifics of the implementation are marked in the code block with a 'TODO' statement. Please be sure to read the instructions carefully!

  1. In addition to implementing code, there will be questions that you must answer which relate to the project and your implementation.

    a. Each section where you will answer a question is preceded by a 'Question X' header.

    b. Carefully read each question and provide thorough answers in the following text boxes that begin with 'Answer:'.

Note: Code and Markdown cells can be executed using the Shift + Enter keyboard shortcut. Markdown cells can be edited by double-clicking the cell to enter edit mode.

The rubric contains optional suggestions for enhancing the project beyond the minimum requirements. If you decide to pursue the "(Optional)" sections, you should include the code in this IPython notebook.

Your project submission will be evaluated based on your answers to each of the questions and the code implementations you provide.

Steps to Complete the Project

Each part of the notebook is further broken down into separate steps. Feel free to use the links below to navigate the notebook.

In this project you will get to explore a few of the many computer vision algorithms built into the OpenCV library. This expansive computer vision library is now almost 20 years old and still growing!

The project itself is broken down into three large parts, then even further into separate steps. Make sure to read through each step, and complete any sections that begin with '(IMPLEMENTATION)' in the header; these implementation sections may contain multiple TODOs that will be marked in code. For convenience, we provide links to each of these steps below.

Part 1 : Investigating OpenCV, pre-processing, and face detection

  • Step 0: Detect Faces Using a Haar Cascade Classifier
  • Step 1: Add Eye Detection
  • Step 2: De-noise an Image for Better Face Detection
  • Step 3: Blur an Image and Perform Edge Detection
  • Step 4: Automatically Hide the Identity of an Individual

Part 2 : Training a Convolutional Neural Network (CNN) to detect facial keypoints

  • Step 5: Create a CNN to Recognize Facial Keypoints
  • Step 6: Compile and Train the Model
  • Step 7: Visualize the Loss and Answer Questions

Part 3 : Putting parts 1 and 2 together to identify facial keypoints on any image!

  • Step 8: Build a Robust Facial Keypoints Detector (Complete the CV Pipeline)

Step 0: Detect Faces Using a Haar Cascade Classifier

Have you ever wondered how Facebook automatically tags images with your friends' faces? Or how high-end cameras automatically find and focus on a certain person's face? Applications like these depend heavily on the machine learning task known as face detection - which is the task of automatically finding faces in images containing people.

At its root face detection is a classification problem - that is a problem of distinguishing between distinct classes of things. With face detection these distinct classes are 1) images of human faces and 2) everything else.

We use OpenCV's implementation of Haar feature-based cascade classifiers to detect human faces in images. OpenCV provides many pre-trained face detectors, stored as XML files on github. We have downloaded one of these detectors and stored it in the detector_architectures directory.

Import Resources

In the next python cell, we load in the required libraries for this section of the project.

In [1]:
# Import required libraries for this section

%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
import math
import cv2                     # OpenCV library for computer vision
from PIL import Image
import time 

Next, we load in and display a test image for performing face detection.

Note: by default OpenCV assumes the ordering of our image's color channels are Blue, then Green, then Red. This is slightly out of order with most image types we'll use in these experiments, whose color channels are ordered Red, then Green, then Blue. In order to switch the Blue and Red channels of our test image around we will use OpenCV's cvtColor function, which you can read more about by checking out some of its documentation located here. This is a general utility function that can do other transformations too like converting a color image to grayscale, and transforming a standard color image to HSV color space.

In [2]:
# Load in color image for face detection
image = cv2.imread('images/test_image_1.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Plot our image using subplots to specify a size and title
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)
Out[2]:
<matplotlib.image.AxesImage at 0x8783080>

There are a lot of people - and faces - in this picture. 13 faces to be exact! In the next code cell, we demonstrate how to use a Haar Cascade classifier to detect all the faces in this test image.

This face detector uses information about patterns of intensity in an image to reliably detect faces under varying light conditions. So, to use this face detector, we'll first convert the image from color to grayscale.

Then, we load in the fully trained architecture of the face detector -- found in the file haarcascade_frontalface_default.xml - and use it on our image to find faces!

To learn more about the parameters of the detector see this post.

In [3]:
# Convert the RGB  image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray, 4, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face Detections')
ax1.imshow(image_with_detections)
Number of faces detected: 13
Out[3]:
<matplotlib.image.AxesImage at 0x44f96a0>

In the above code, faces is a numpy array of detected faces, where each row corresponds to a detected face. Each detected face is a 1D array with four entries that specifies the bounding box of the detected face. The first two entries in the array (extracted in the above code as x and y) specify the horizontal and vertical positions of the top left corner of the bounding box. The last two entries in the array (extracted here as w and h) specify the width and height of the box.


Step 1: Add Eye Detections

There are other pre-trained detectors available that use a Haar Cascade Classifier - including full human body detectors, license plate detectors, and more. A full list of the pre-trained architectures can be found here.

To test your eye detector, we'll first read in a new test image with just a single face.

In [4]:
# Load in color image for face detection
image = cv2.imread('images/james.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Plot the RGB image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)
Out[4]:
<matplotlib.image.AxesImage at 0x45381d0>

Notice that even though the image is a black and white image, we have read it in as a color image and so it will still need to be converted to grayscale in order to perform the most accurate face detection.

So, the next steps will be to convert this image to grayscale, then load OpenCV's face detector and run it with parameters that detect this face accurately.

In [5]:
# Convert the RGB  image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray, 1.25, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face Detection')
ax1.imshow(image_with_detections)
Number of faces detected: 1
Out[5]:
<matplotlib.image.AxesImage at 0x45702b0>

(IMPLEMENTATION) Add an eye detector to the current face detection setup.

A Haar-cascade eye detector can be included in the same way that the face detector was and, in this first task, it will be your job to do just this.

To set up an eye detector, use the stored parameters of the eye cascade detector, called haarcascade_eye.xml, located in the detector_architectures subdirectory. In the next code cell, create your eye detector and store its detections.

A few notes before you get started:

First, make sure to give your loaded eye detector the variable name

eye_cascade

and give the list of eye regions you detect the variable name

eyes

Second, since we've already run the face detector over this image, you should only search for eyes within the rectangular face regions detected in faces. This will minimize false detections.

Lastly, once you've run your eye detector over the facial detection region, you should display the RGB image with both the face detection boxes (in red) and your eye detections (in green) to verify that everything works as expected.

In [6]:
# Make a copy of the original image to plot rectangle detections
image_with_detections = np.copy(image)   

# Loop over the detections and draw their corresponding face detection boxes
for (x,y,w,h) in faces:
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h),(255,0,0), 3)  
    
# Do not change the code above this comment!
    
## TODO: Add eye detection, using haarcascade_eye.xml, to the current face detector algorithm
## TODO: Loop over the eye detections and draw their corresponding boxes in green on image_with_detections

# Extract the pre-trained eye detector from an xml file
eye_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_eye.xml')
# Detect the eyes in image
eyes = eye_cascade.detectMultiScale(gray, 1.04, 4)

# Get the bounding box for each detected eye
for (x,y,w,h) in eyes:
    # Add a green bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (0,255,0), 3)

# Plot the image with both faces and eyes detected
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face and Eye Detection')
ax1.imshow(image_with_detections)
Out[6]:
<matplotlib.image.AxesImage at 0x45a0b70>

(Optional) Add face and eye detection to your laptop camera

It's time to kick it up a notch, and add face and eye detection to your laptop's camera! Afterwards, you'll be able to show off your creation like in the gif shown below - made with a completed version of the code!

Notice that not all of the detections here are perfect - and your result need not be perfect either. You should spend a small amount of time tuning the parameters of your detectors to get reasonable results, but don't hold out for perfection. If we wanted perfection we'd need to spend a ton of time tuning the parameters of each detector, cleaning up the input image frames, etc. You can think of this as more of a rapid prototype.

The next cell contains code for a wrapper function called laptop_camera_face_eye_detector that, when called, will activate your laptop's camera. You will place the relevant face and eye detection code in this wrapper function to implement face/eye detection and mark those detections on each image frame that your camera captures.

Before adding anything to the function, you can run it to get an idea of how it works - a small window should pop up showing you the live feed from your camera; you can press any key to close this window.

Note: Mac users may find that activating this function kills the kernel of their notebook every once in a while. If this happens to you, just restart your notebook's kernel, activate cell(s) containing any crucial import statements, and you'll be good to go!

In [7]:
### Add face and eye detection to this laptop camera function 
# Make sure to draw out all faces/eyes found in each frame on the shown video feed

import cv2
import time 

# wrapper function for face/eye detection with your laptop camera
def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep the video stream open
    while rval:
      
        faces = face_cascade.detectMultiScale(frame, 1.1, 5)
        for (x,y,w,h) in faces:
            img = cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
            roi_gray = frame[y:y+h, x:x+w]
            roi_color = img[y:y+h, x:x+w]
            eyes = eye_cascade.detectMultiScale(roi_gray)
            for (ex,ey,ew,eh) in eyes:
                cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
        
                
        # Plot the image from camera with all the face and eye detections marked
        cv2.imshow("face detection activated", frame)              
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        # Exit this loop on escape:
        if(key == 27) :
            # Destroy windows 
            cv2.destroyAllWindows()
            break;
            
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
In [8]:
# Call the laptop camera face/eye detector function above
laptop_camera_go()

Step 2: De-noise an Image for Better Face Detection

Image quality is an important aspect of any computer vision task. Typically, when creating a set of images to train a deep learning network, significant care is taken to ensure that training images are free of visual noise or artifacts that hinder object detection. While computer vision algorithms - like a face detector - are typically trained on 'nice' data such as this, new test data doesn't always look so nice!

When applying a trained computer vision algorithm to a new piece of test data one often cleans it up first before feeding it in. This sort of cleaning - referred to as pre-processing - can include a number of cleaning phases like blurring, de-noising, color transformations, etc., and many of these tasks can be accomplished using OpenCV.

In this short subsection we explore OpenCV's noise-removal functionality to see how we can clean up a noisy image, which we then feed into our trained face detector.

Create a noisy image to work with

In the next cell, we create an artificial noisy version of the previous multi-face image. This is a little exaggerated - we don't typically get images that are this noisy - but image noise, or 'grainy-ness' in a digitial image - is a fairly common phenomenon.

In [16]:
# Load in the multi-face test image again
image = cv2.imread('images/test_image_1.jpg')

# Convert the image copy to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Make an array copy of this image
image_with_noise = np.asarray(image)

# Create noise - here we add noise sampled randomly from a Gaussian distribution: a common model for noise
noise_level = 40
noise = np.random.randn(image.shape[0],image.shape[1],image.shape[2])*noise_level

# Add this noise to the array image copy
image_with_noise = image_with_noise + noise

# Convert back to uint8 format
image_with_noise = np.asarray([np.uint8(np.clip(i,0,255)) for i in image_with_noise])

# Plot our noisy image!
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Noisy Image')
ax1.imshow(image_with_noise)
Out[16]:
<matplotlib.image.AxesImage at 0x832e128>

In the context of face detection, the problem with an image like this is that - due to noise - we may miss some faces or get false detections.

In the next cell we apply the same trained OpenCV detector with the same settings as before, to see what sort of detections we get.

In [17]:
# Convert the RGB  image to grayscale
gray_noise = cv2.cvtColor(image_with_noise, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray_noise, 4, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image_with_noise)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Noisy Image with Face Detections')
ax1.imshow(image_with_detections)
Number of faces detected: 12
Out[17]:
<matplotlib.image.AxesImage at 0x85a15c0>

With this added noise we now miss one of the faces!

(IMPLEMENTATION) De-noise this image for better face detection

Time to get your hands dirty: using OpenCV's built in color image de-noising functionality called fastNlMeansDenoisingColored - de-noise this image enough so that all the faces in the image are properly detected. Once you have cleaned the image in the next cell, use the cell that follows to run our trained face detector over the cleaned image to check out its detections.

You can find its official documentation here and a useful example here.

Note: you can keep all parameters except photo_render fixed as shown in the second link above. Play around with the value of this parameter - see how it affects the resulting cleaned image.

In [19]:
## TODO: Use OpenCV's built in color image de-noising function to clean up our noisy image!

#denoised_image = # your final de-noised image (should be RGB)
denoised_image = cv2.fastNlMeansDenoisingColored(image_with_noise, None, 10,10,7,21)

# Display the denoised_image
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Denoised Image')
ax1.imshow(denoised_image)
Out[19]:
<matplotlib.image.AxesImage at 0x83a16d8>
In [20]:
## TODO: Run the face detector on the de-noised image to improve your detections and display the result

# Convert the RGB  image to grayscale
gray_noise_denoise = cv2.cvtColor(denoised_image, cv2.COLOR_RGB2GRAY)

# Detect the faces in image
faces_denoise = face_cascade.detectMultiScale(gray_noise_denoise, 1.2, 5)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces_denoise))

# Make a copy of the orginal image to draw face detections on
image_with_detections_denoise = np.copy(denoised_image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces_denoise:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections_denoise, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('DeNoised Image with Face Detections')
ax1.imshow(image_with_detections_denoise)
Number of faces detected: 13
Out[20]:
<matplotlib.image.AxesImage at 0x83d7630>

Step 3: Blur an Image and Perform Edge Detection

Now that we have developed a simple pipeline for detecting faces using OpenCV - let's start playing around with a few fun things we can do with all those detected faces!

Importance of Blur in Edge Detection

Edge detection is a concept that pops up almost everywhere in computer vision applications, as edge-based features (as well as features built on top of edges) are often some of the best features for e.g., object detection and recognition problems.

Edge detection is a dimension reduction technique - by keeping only the edges of an image we get to throw away a lot of non-discriminating information. And typically the most useful kind of edge-detection is one that preserves only the important, global structures (ignoring local structures that aren't very discriminative). So removing local structures / retaining global structures is a crucial pre-processing step to performing edge detection in an image, and blurring can do just that.

Below is an animated gif showing the result of an edge-detected cat taken from Wikipedia, where the image is gradually blurred more and more prior to edge detection. When the animation begins you can't quite make out what it's a picture of, but as the animation evolves and local structures are removed via blurring the cat becomes visible in the edge-detected image.

Edge detection is a convolution performed on the image itself, and you can read about Canny edge detection on this OpenCV documentation page.

Canny edge detection

In the cell below we load in a test image, then apply Canny edge detection on it. The original image is shown on the left panel of the figure, while the edge-detected version of the image is shown on the right. Notice how the result looks very busy - there are too many little details preserved in the image before it is sent to the edge detector. When applied in computer vision applications, edge detection should preserve global structure; doing away with local structures that don't help describe what objects are in the image.

In [13]:
# Load in the image
image = cv2.imread('images/fawzia.jpg')

# Convert to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)  

# Perform Canny edge detection
edges = cv2.Canny(gray,100,200)

# Dilate the image to amplify edges
edges = cv2.dilate(edges, None)

# Plot the RGB and edge-detected image
fig = plt.figure(figsize = (15,15))
ax1 = fig.add_subplot(121)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)

ax2 = fig.add_subplot(122)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('Canny Edges')
ax2.imshow(edges, cmap='gray')
Out[13]:
<matplotlib.image.AxesImage at 0x82aa2b0>

Without first blurring the image, and removing small, local structures, a lot of irrelevant edge content gets picked up and amplified by the detector (as shown in the right panel above).

(IMPLEMENTATION) Blur the image then perform edge detection

In the next cell, you will repeat this experiment - blurring the image first to remove these local structures, so that only the important boudnary details remain in the edge-detected image.

Blur the image by using OpenCV's filter2d functionality - which is discussed in this documentation page - and use an averaging kernel of width equal to 4.

In [14]:
### TODO: Blur the test image using OpenCV's filter2d functionality, 
# Use an averaging kernel, and a kernel width equal to 4

# Load in the image
image = cv2.imread('images/fawzia.jpg')
kernel = np.ones((4,4),np.float32)/16
blur_image = cv2.filter2D(image,-1,kernel) 
   
## TODO: Then perform Canny edge detection and display the output

# Perform Canny edge detection
blur_image_edges = cv2.Canny(blur_image,100,200)

# Dilate the image to amplify edges
dilated_blur_image = cv2.dilate(blur_image_edges, None)

# Plot the RGB and edge-detected image
fig = plt.figure(figsize = (15,15))
ax1 = fig.add_subplot(121)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)

ax2 = fig.add_subplot(122)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('Canny Edges')
ax2.imshow(dilated_blur_image, cmap='gray')
Out[14]:
<matplotlib.image.AxesImage at 0x83155f8>

Step 4: Automatically Hide the Identity of an Individual

If you film something like a documentary or reality TV, you must get permission from every individual shown on film before you can show their face, otherwise you need to blur it out - by blurring the face a lot (so much so that even the global structures are obscured)! This is also true for projects like Google's StreetView maps - an enormous collection of mapping images taken from a fleet of Google vehicles. Because it would be impossible for Google to get the permission of every single person accidentally captured in one of these images they blur out everyone's faces, the detected images must automatically blur the identity of detected people. Here's a few examples of folks caught in the camera of a Google street view vehicle.

Read in an image to perform identity detection

Let's try this out for ourselves. Use the face detection pipeline built above and what you know about using the filter2D to blur and image, and use these in tandem to hide the identity of the person in the following image - loaded in and printed in the next cell.

In [15]:
# Load in the image
image = cv2.imread('images/gus.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Display the image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Original Image')
ax1.imshow(image)
Out[15]:
<matplotlib.image.AxesImage at 0x85df198>

(IMPLEMENTATION) Use blurring to hide the identity of an individual in an image

The idea here is to 1) automatically detect the face in this image, and then 2) blur it out! Make sure to adjust the parameters of the averaging blur filter to completely obscure this person's identity.

In [16]:
## TODO: Implement face detection

# Convert the RGB  image to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray_image, 1.3, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(gray))

# Make a copy of the orginal image to draw face detections on
face_detected_image = np.copy(image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(face_detected_image, (x,y), (x+w,y+h), (255,0,0), 3)
    cropped_face = face_detected_image[y:y+h, x:x+w]
    
## TODO: Blur the bounding box around each detected face using an averaging filter and display the result
blurred_face_image = np.copy(image)
kernel = np.ones((100,100),np.float32)/10000
blur = cv2.filter2D(cropped_face,-1,kernel)
blurred_face_image[y:y+blur.shape[0], x:x+blur.shape[1]] = blur
   
# Plot the RGB and edge-detected image
fig = plt.figure(figsize = (15,15))
ax1 = fig.add_subplot(121)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(face_detected_image)

ax2 = fig.add_subplot(122)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('Blurred Image')
ax2.imshow(blurred_face_image, cmap='gray')
Number of faces detected: 665
Out[16]:
<matplotlib.image.AxesImage at 0x86dffd0>

(Optional) Build identity protection into your laptop camera

In this optional task you can add identity protection to your laptop camera, using the previously completed code where you added face detection to your laptop camera - and the task above. You should be able to get reasonable results with little parameter tuning - like the one shown in the gif below.

As with the previous video task, to make this perfect would require significant effort - so don't strive for perfection here, strive for reasonable quality.

The next cell contains code a wrapper function called laptop_camera_identity_hider that - when called - will activate your laptop's camera. You need to place the relevant face detection and blurring code developed above in this function in order to blur faces entering your laptop camera's field of view.

Before adding anything to the function you can call it to get a hang of how it works - a small window will pop up showing you the live feed from your camera, you can press any key to close this window.

Note: Mac users may find that activating this function kills the kernel of their notebook every once in a while. If this happens to you, just restart your notebook's kernel, activate cell(s) containing any crucial import statements, and you'll be good to go!

In [17]:
### Insert face detection and blurring code into the wrapper below to create an identity protector on your laptop!
import cv2
import time 

kernal = np.ones((100,100), dtype=np.float32)/10000
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep video stream open
    while rval:
  
        faces = face_cascade.detectMultiScale(frame, 1.1, 5)        
        for (x,y,w,h) in faces:
            frame[y:y+w,x:x+h] = cv2.filter2D(frame[y:y+w,x:x+h], -1, kernal)
            cv2.rectangle(frame, (x,y), (x+w,y+h),(255,120,150), 5)

        # Plot image from camera with detections marked
        cv2.imshow("face detection activated", frame)
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        # Exit this loop on escape:
        if(key == 27) :
            # Destroy windows 
            cv2.destroyAllWindows()
            break;
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
        
In [18]:
# Run laptop identity hider
laptop_camera_go()

Step 5: Create a CNN to Recognize Facial Keypoints

OpenCV is often used in practice with other machine learning and deep learning libraries to produce interesting results. In this stage of the project you will create your own end-to-end pipeline - employing convolutional networks in keras along with OpenCV - to apply a "selfie" filter to streaming video and images.

You will start by creating and then training a convolutional network that can detect facial keypoints in a small dataset of cropped images of human faces. We then guide you towards OpenCV to expanding your detection algorithm to more general images. What are facial keypoints? Let's take a look at some examples.

Facial keypoints (also called facial landmarks) are the small blue-green dots shown on each of the faces in the image above - there are 15 keypoints marked in each image. They mark important areas of the face - the eyes, corners of the mouth, the nose, etc. Facial keypoints can be used in a variety of machine learning applications from face and emotion recognition to commercial applications like the image filters popularized by Snapchat.

Below we illustrate a filter that, using the results of this section, automatically places sunglasses on people in images (using the facial keypoints to place the glasses correctly on each face). Here, the facial keypoints have been colored lime green for visualization purposes.

Make a facial keypoint detector

But first things first: how can we make a facial keypoint detector? Well, at a high level, notice that facial keypoint detection is a regression problem. A single face corresponds to a set of 15 facial keypoints (a set of 15 corresponding $(x, y)$ coordinates, i.e., an output point). Because our input data are images, we can employ a convolutional neural network to recognize patterns in our images and learn how to identify these keypoint given sets of labeled data.

In order to train a regressor, we need a training set - a set of facial image / facial keypoint pairs to train on. For this we will be using this dataset from Kaggle. We've already downloaded this data and placed it in the data directory. Make sure that you have both the training and test data files. The training dataset contains several thousand $96 \times 96$ grayscale images of cropped human faces, along with each face's 15 corresponding facial keypoints (also called landmarks) that have been placed by hand, and recorded in $(x, y)$ coordinates. This wonderful resource also has a substantial testing set, which we will use in tinkering with our convolutional network.

To load in this data, run the Python cell below - notice we will load in both the training and testing sets.

The load_data function is in the included utils.py file.

In [21]:
from utils import *

# Load training set
X_train, y_train = load_data()
print("X_train.shape == {}".format(X_train.shape))
print("y_train.shape == {}; y_train.min == {:.3f}; y_train.max == {:.3f}".format(
    y_train.shape, y_train.min(), y_train.max()))

# Load testing set
X_test, _ = load_data(test=True)
print("X_test.shape == {}".format(X_test.shape))
Using TensorFlow backend.
X_train.shape == (2140, 96, 96, 1)
y_train.shape == (2140, 30); y_train.min == -0.920; y_train.max == 0.996
X_test.shape == (1783, 96, 96, 1)

The load_data function in utils.py originates from this excellent blog post, which you are strongly encouraged to read. Please take the time now to review this function. Note how the output values - that is, the coordinates of each set of facial landmarks - have been normalized to take on values in the range $[-1, 1]$, while the pixel values of each input point (a facial image) have been normalized to the range $[0,1]$.

Note: the original Kaggle dataset contains some images with several missing keypoints. For simplicity, the load_data function removes those images with missing labels from the dataset. As an optional extension, you are welcome to amend the load_data function to include the incomplete data points.

Visualize the Training Data

Execute the code cell below to visualize a subset of the training data.

In [20]:
import matplotlib.pyplot as plt
%matplotlib inline

fig = plt.figure(figsize=(20,20))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
for i in range(9):
    ax = fig.add_subplot(3, 3, i + 1, xticks=[], yticks=[])
    plot_data(X_train[i], y_train[i], ax)

For each training image, there are two landmarks per eyebrow (four total), three per eye (six total), four for the mouth, and one for the tip of the nose.

Review the plot_data function in utils.py to understand how the 30-dimensional training labels in y_train are mapped to facial locations, as this function will prove useful for your pipeline.

(IMPLEMENTATION) Specify the CNN Architecture

In this section, you will specify a neural network for predicting the locations of facial keypoints. Use the code cell below to specify the architecture of your neural network. We have imported some layers that you may find useful for this task, but if you need to use more Keras layers, feel free to import them in the cell.

Your network should accept a $96 \times 96$ grayscale image as input, and it should output a vector with 30 entries, corresponding to the predicted (horizontal and vertical) locations of 15 facial keypoints. If you are not sure where to start, you can find some useful starting architectures in this blog, but you are not permitted to copy any of the architectures that you find online.

In [137]:
# Start with a new model; same architechture# Start w 
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Dropout, GlobalAveragePooling2D, BatchNormalization
from keras.layers import Flatten, Dense

## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)

model = Sequential()
# conv layer 1
model.add(Conv2D(filters=16, kernel_size=3, activation='relu', input_shape=(96, 96, 1)))
model.add(MaxPooling2D(pool_size=2))

# conv layer 2
model.add(Conv2D(filters=32, kernel_size=3, activation='relu'))
model.add(MaxPooling2D(pool_size=2))

# conv layer 3
model.add(Conv2D(filters=64, kernel_size=3, activation='relu'))
model.add(MaxPooling2D(pool_size=2))

# conv layer 4
model.add(Conv2D(filters=128, kernel_size=3, activation='relu'))
model.add(MaxPooling2D(pool_size=2))

#Flatten Layer
model.add(Flatten())

# Fully connected layer 1
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.2))

# Fully connected layer 2
model.add(Dense(30))

# Summarize the model
model.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_54 (Conv2D)           (None, 94, 94, 16)        160       
_________________________________________________________________
max_pooling2d_54 (MaxPooling (None, 47, 47, 16)        0         
_________________________________________________________________
conv2d_55 (Conv2D)           (None, 45, 45, 32)        4640      
_________________________________________________________________
max_pooling2d_55 (MaxPooling (None, 22, 22, 32)        0         
_________________________________________________________________
conv2d_56 (Conv2D)           (None, 20, 20, 64)        18496     
_________________________________________________________________
max_pooling2d_56 (MaxPooling (None, 10, 10, 64)        0         
_________________________________________________________________
conv2d_57 (Conv2D)           (None, 8, 8, 128)         73856     
_________________________________________________________________
max_pooling2d_57 (MaxPooling (None, 4, 4, 128)         0         
_________________________________________________________________
flatten_13 (Flatten)         (None, 2048)              0         
_________________________________________________________________
dense_22 (Dense)             (None, 512)               1049088   
_________________________________________________________________
dropout_56 (Dropout)         (None, 512)               0         
_________________________________________________________________
dense_23 (Dense)             (None, 30)                15390     
=================================================================
Total params: 1,161,630
Trainable params: 1,161,630
Non-trainable params: 0
_________________________________________________________________

Step 6: Compile and Train the Model

After specifying your architecture, you'll need to compile and train the model to detect facial keypoints'

(IMPLEMENTATION) Compile and Train the Model

Use the compile method to configure the learning process. Experiment with your choice of optimizer; you may have some ideas about which will work best (SGD vs. RMSprop, etc), but take the time to empirically verify your theories.

Use the fit method to train the model. Break off a validation set by setting validation_split=0.2. Save the returned History object in the history variable.

Experiment with your model to minimize the validation loss (measured as mean squared error). A very good model will achieve about 0.0015 loss (though it's possible to do even better). When you have finished training, save your model as an HDF5 file with file path my_model.h5.

Choosing Optimizer

In [99]:
from keras.optimizers import SGD, RMSprop, Adagrad, Adadelta, Adam, Adamax, Nadam
from keras.callbacks import ModelCheckpoint, History

history = {}
epochs = 30
batch_size = 16

## Tune the optimizer
optimizers = [SGD(), RMSprop(), Adagrad(), Adadelta(), Adam(), Adamax(), Nadam()]
opt_names = ["CNN_SGD", "CNN_RMSprop", "CNN_Adagrad", "CNN_Adadelta", "CNN_Adam", "CNN_Adamax", "CNN_Nadam"]

for optimizer, name in zip(optimizers, opt_names):
    print("Checking " + name)
    
    ## TODO: Compile the model
    model.compile(optimizer = optimizer, loss = 'mean_squared_error', metrics = ['mse'])
    checkpointer = ModelCheckpoint(filepath = "saved_models/weights_best_val_MSE_" + name + ".hdf5",
                                   verbose = 1, save_best_only = True)
    history[name] = model.fit(X_train, y_train, validation_split = 0.2, epochs = epochs, batch_size = batch_size, callbacks = [checkpointer], verbose = 1)
Checking CNN_SGD
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0709 - mean_squared_error: 0.0709Epoch 00001: val_loss improved from inf to 0.01240, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 25s 15ms/step - loss: 0.0704 - mean_squared_error: 0.0704 - val_loss: 0.0124 - val_mean_squared_error: 0.0124
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0169 - mean_squared_error: 0.0169Epoch 00002: val_loss improved from 0.01240 to 0.00836, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0169 - mean_squared_error: 0.0169 - val_loss: 0.0084 - val_mean_squared_error: 0.0084
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0149 - mean_squared_error: 0.0149Epoch 00003: val_loss improved from 0.00836 to 0.00784, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0149 - mean_squared_error: 0.0149 - val_loss: 0.0078 - val_mean_squared_error: 0.0078
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0138 - mean_squared_error: 0.0138Epoch 00004: val_loss improved from 0.00784 to 0.00727, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 31s 18ms/step - loss: 0.0138 - mean_squared_error: 0.0138 - val_loss: 0.0073 - val_mean_squared_error: 0.0073
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0128 - mean_squared_error: 0.0128Epoch 00005: val_loss improved from 0.00727 to 0.00690, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 28s 16ms/step - loss: 0.0129 - mean_squared_error: 0.0129 - val_loss: 0.0069 - val_mean_squared_error: 0.0069
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0122 - mean_squared_error: 0.0122Epoch 00006: val_loss improved from 0.00690 to 0.00669, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 26s 15ms/step - loss: 0.0122 - mean_squared_error: 0.0122 - val_loss: 0.0067 - val_mean_squared_error: 0.0067
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0115 - mean_squared_error: 0.0115Epoch 00007: val_loss improved from 0.00669 to 0.00636, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0114 - mean_squared_error: 0.0114 - val_loss: 0.0064 - val_mean_squared_error: 0.0064
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0109 - mean_squared_error: 0.0109Epoch 00008: val_loss improved from 0.00636 to 0.00616, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0109 - mean_squared_error: 0.0109 - val_loss: 0.0062 - val_mean_squared_error: 0.0062
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0105 - mean_squared_error: 0.0105Epoch 00009: val_loss improved from 0.00616 to 0.00614, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0105 - mean_squared_error: 0.0105 - val_loss: 0.0061 - val_mean_squared_error: 0.0061
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0102 - mean_squared_error: 0.0102Epoch 00010: val_loss improved from 0.00614 to 0.00573, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0102 - mean_squared_error: 0.0102 - val_loss: 0.0057 - val_mean_squared_error: 0.0057
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0098 - mean_squared_error: 0.0098Epoch 00011: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0098 - mean_squared_error: 0.0098 - val_loss: 0.0057 - val_mean_squared_error: 0.0057
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0096 - mean_squared_error: 0.0096Epoch 00012: val_loss improved from 0.00573 to 0.00545, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0096 - mean_squared_error: 0.0096 - val_loss: 0.0055 - val_mean_squared_error: 0.0055
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0093 - mean_squared_error: 0.0093Epoch 00013: val_loss improved from 0.00545 to 0.00527, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0093 - mean_squared_error: 0.0093 - val_loss: 0.0053 - val_mean_squared_error: 0.0053
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0090 - mean_squared_error: 0.0090Epoch 00014: val_loss improved from 0.00527 to 0.00519, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0089 - mean_squared_error: 0.0089 - val_loss: 0.0052 - val_mean_squared_error: 0.0052
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0087 - mean_squared_error: 0.0087Epoch 00015: val_loss improved from 0.00519 to 0.00513, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0087 - mean_squared_error: 0.0087 - val_loss: 0.0051 - val_mean_squared_error: 0.0051
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0087 - mean_squared_error: 0.0087Epoch 00016: val_loss improved from 0.00513 to 0.00505, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0087 - mean_squared_error: 0.0087 - val_loss: 0.0050 - val_mean_squared_error: 0.0050
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0084 - mean_squared_error: 0.0084Epoch 00017: val_loss improved from 0.00505 to 0.00491, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0084 - mean_squared_error: 0.0084 - val_loss: 0.0049 - val_mean_squared_error: 0.0049
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0083 - mean_squared_error: 0.0083Epoch 00018: val_loss improved from 0.00491 to 0.00482, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0083 - mean_squared_error: 0.0083 - val_loss: 0.0048 - val_mean_squared_error: 0.0048
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0081 - mean_squared_error: 0.0081Epoch 00019: val_loss improved from 0.00482 to 0.00476, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0081 - mean_squared_error: 0.0081 - val_loss: 0.0048 - val_mean_squared_error: 0.0048
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0080 - mean_squared_error: 0.0080Epoch 00020: val_loss improved from 0.00476 to 0.00475, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0080 - mean_squared_error: 0.0080 - val_loss: 0.0048 - val_mean_squared_error: 0.0048
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0079 - mean_squared_error: 0.0079 ETA: 1s - loss: 0.0079 - mean_squared_eEpoch 00021: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0079 - mean_squared_error: 0.0079 - val_loss: 0.0048 - val_mean_squared_error: 0.0048
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0078 - mean_squared_error: 0.0078Epoch 00022: val_loss improved from 0.00475 to 0.00473, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0078 - mean_squared_error: 0.0078 - val_loss: 0.0047 - val_mean_squared_error: 0.0047
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0077 - mean_squared_error: 0.0077Epoch 00023: val_loss improved from 0.00473 to 0.00471, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0077 - mean_squared_error: 0.0077 - val_loss: 0.0047 - val_mean_squared_error: 0.0047
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0076 - mean_squared_error: 0.0076Epoch 00024: val_loss improved from 0.00471 to 0.00458, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0076 - mean_squared_error: 0.0076 - val_loss: 0.0046 - val_mean_squared_error: 0.0046
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0076 - mean_squared_error: 0.0076Epoch 00025: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0076 - mean_squared_error: 0.0076 - val_loss: 0.0046 - val_mean_squared_error: 0.0046
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0075 - mean_squared_error: 0.0075Epoch 00026: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0075 - mean_squared_error: 0.0075 - val_loss: 0.0046 - val_mean_squared_error: 0.0046
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0074 - mean_squared_error: 0.0074Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0074 - mean_squared_error: 0.0074 - val_loss: 0.0047 - val_mean_squared_error: 0.0047
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0073 - mean_squared_error: 0.0073Epoch 00028: val_loss improved from 0.00458 to 0.00456, saving model to saved_models/weights_best_val_MSE_CNN_SGD.hdf5
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0073 - mean_squared_error: 0.0073 - val_loss: 0.0046 - val_mean_squared_error: 0.0046
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0074 - mean_squared_error: 0.0074Epoch 00029: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0074 - mean_squared_error: 0.0074 - val_loss: 0.0046 - val_mean_squared_error: 0.0046
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0072 - mean_squared_error: 0.0072 ETA: 4s -Epoch 00030: val_loss did not improve
1712/1712 [==============================] - 21s 13ms/step - loss: 0.0072 - mean_squared_error: 0.0072 - val_loss: 0.0046 - val_mean_squared_error: 0.0046
Checking CNN_RMSprop
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0190 - mean_squared_error: 0.0190 ETA: 2s - loss: 0.0204 - meEpoch 00001: val_loss improved from inf to 0.00550, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 25s 15ms/step - loss: 0.0189 - mean_squared_error: 0.0189 - val_loss: 0.0055 - val_mean_squared_error: 0.0055
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0067 - mean_squared_error: 0.0067Epoch 00002: val_loss improved from 0.00550 to 0.00462, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0067 - mean_squared_error: 0.0067 - val_loss: 0.0046 - val_mean_squared_error: 0.0046
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0060 - mean_squared_error: 0.0060 ETA: 3s - losEpoch 00003: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0060 - mean_squared_error: 0.0060 - val_loss: 0.0047 - val_mean_squared_error: 0.0047
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0056 - mean_squared_error: 0.0056Epoch 00004: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0056 - mean_squared_error: 0.0056 - val_loss: 0.0051 - val_mean_squared_error: 0.0051
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0049 - mean_squared_error: 0.0049Epoch 00005: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0049 - mean_squared_error: 0.0049 - val_loss: 0.0050 - val_mean_squared_error: 0.0050
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0040 - mean_squared_error: 0.0040Epoch 00006: val_loss improved from 0.00462 to 0.00255, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0040 - mean_squared_error: 0.0040 - val_loss: 0.0026 - val_mean_squared_error: 0.0026
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0033 - mean_squared_error: 0.0033Epoch 00007: val_loss improved from 0.00255 to 0.00235, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0033 - mean_squared_error: 0.0033 - val_loss: 0.0024 - val_mean_squared_error: 0.0024
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0028 - mean_squared_error: 0.0028Epoch 00008: val_loss improved from 0.00235 to 0.00196, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0028 - mean_squared_error: 0.0028 - val_loss: 0.0020 - val_mean_squared_error: 0.0020
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0025 - mean_squared_error: 0.0025Epoch 00009: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0025 - mean_squared_error: 0.0025 - val_loss: 0.0024 - val_mean_squared_error: 0.0024
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0023 - mean_squared_error: 0.0023Epoch 00010: val_loss improved from 0.00196 to 0.00164, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0023 - mean_squared_error: 0.0023 - val_loss: 0.0016 - val_mean_squared_error: 0.0016
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0020 - mean_squared_error: 0.0020Epoch 00011: val_loss improved from 0.00164 to 0.00156, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0020 - mean_squared_error: 0.0020 - val_loss: 0.0016 - val_mean_squared_error: 0.0016
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0019 - mean_squared_error: 0.0019Epoch 00012: val_loss improved from 0.00156 to 0.00141, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0019 - mean_squared_error: 0.0019 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0017 - mean_squared_error: 0.0017Epoch 00013: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0017 - mean_squared_error: 0.0017 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - mean_squared_error: 0.0016Epoch 00014: val_loss improved from 0.00141 to 0.00135, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0016 - mean_squared_error: 0.0016 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - mean_squared_error: 0.0014Epoch 00015: val_loss improved from 0.00135 to 0.00125, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0014 - mean_squared_error: 0.0014 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - mean_squared_error: 0.0013Epoch 00016: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0013 - mean_squared_error: 0.0013 - val_loss: 0.0016 - val_mean_squared_error: 0.0016
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - mean_squared_error: 0.0013Epoch 00017: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0013 - mean_squared_error: 0.0013 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - mean_squared_error: 0.0012Epoch 00018: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0012 - mean_squared_error: 0.0012 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - mean_squared_error: 0.0011Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0011 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - mean_squared_error: 0.0011Epoch 00020: val_loss improved from 0.00125 to 0.00124, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0011 - mean_squared_error: 0.0011 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.8869e-04 - mean_squared_error: 9.8869e-04Epoch 00021: val_loss improved from 0.00124 to 0.00123, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 9.8970e-04 - mean_squared_error: 9.8970e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.4732e-04 - mean_squared_error: 9.4732e-04Epoch 00022: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 9.5256e-04 - mean_squared_error: 9.5256e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.1924e-04 - mean_squared_error: 9.1924e-04Epoch 00023: val_loss improved from 0.00123 to 0.00118, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 9.1778e-04 - mean_squared_error: 9.1778e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.8978e-04 - mean_squared_error: 8.8978e-04Epoch 00024: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 8.8997e-04 - mean_squared_error: 8.8997e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.3733e-04 - mean_squared_error: 8.3733e-04Epoch 00025: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 8.3845e-04 - mean_squared_error: 8.3845e-04 - val_loss: 0.0015 - val_mean_squared_error: 0.0015
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.2405e-04 - mean_squared_error: 8.2405e-04Epoch 00026: val_loss improved from 0.00118 to 0.00113, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 8.2292e-04 - mean_squared_error: 8.2292e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 7.8866e-04 - mean_squared_error: 7.8866e-04Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 7.8700e-04 - mean_squared_error: 7.8700e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 7.5422e-04 - mean_squared_error: 7.5422e-04 ETA: 2s - loss: 7.5830e-04 - meEpoch 00028: val_loss improved from 0.00113 to 0.00113, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 7.5605e-04 - mean_squared_error: 7.5605e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 7.3628e-04 - mean_squared_error: 7.3628e-04Epoch 00029: val_loss improved from 0.00113 to 0.00112, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 7.3516e-04 - mean_squared_error: 7.3516e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 7.0054e-04 - mean_squared_error: 7.0054e-04Epoch 00030: val_loss improved from 0.00112 to 0.00106, saving model to saved_models/weights_best_val_MSE_CNN_RMSprop.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 6.9797e-04 - mean_squared_error: 6.9797e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Checking CNN_Adagrad
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0037 - mean_squared_error: 0.0037 ETA: 4s - loss: 0.0043 - mean_squared - ETA: 3s - loss: 0.0041 - Epoch 00001: val_loss improved from inf to 0.00122, saving model to saved_models/weights_best_val_MSE_CNN_Adagrad.hdf5
1712/1712 [==============================] - 25s 15ms/step - loss: 0.0036 - mean_squared_error: 0.0036 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.1103e-04 - mean_squared_error: 8.1103e-04Epoch 00002: val_loss improved from 0.00122 to 0.00107, saving model to saved_models/weights_best_val_MSE_CNN_Adagrad.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 8.0904e-04 - mean_squared_error: 8.0904e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 6.5577e-04 - mean_squared_error: 6.5577e-04Epoch 00003: val_loss improved from 0.00107 to 0.00105, saving model to saved_models/weights_best_val_MSE_CNN_Adagrad.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 6.5467e-04 - mean_squared_error: 6.5467e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 5.7057e-04 - mean_squared_error: 5.7057e-04 ETA: 1s - loss: 5.7265e-04 - mean_squared_error: Epoch 00004: val_loss improved from 0.00105 to 0.00102, saving model to saved_models/weights_best_val_MSE_CNN_Adagrad.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 5.7170e-04 - mean_squared_error: 5.7170e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 5.2578e-04 - mean_squared_error: 5.2578e-04Epoch 00005: val_loss improved from 0.00102 to 0.00102, saving model to saved_models/weights_best_val_MSE_CNN_Adagrad.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 5.2593e-04 - mean_squared_error: 5.2593e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 5.0073e-04 - mean_squared_error: 5.0073e-04Epoch 00006: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 4.9949e-04 - mean_squared_error: 4.9949e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.7048e-04 - mean_squared_error: 4.7048e-04Epoch 00007: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 4.7145e-04 - mean_squared_error: 4.7145e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.5468e-04 - mean_squared_error: 4.5468e-04Epoch 00008: val_loss improved from 0.00102 to 0.00100, saving model to saved_models/weights_best_val_MSE_CNN_Adagrad.hdf5
1712/1712 [==============================] - 21s 12ms/step - loss: 4.5551e-04 - mean_squared_error: 4.5551e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.3831e-04 - mean_squared_error: 4.3831e-04Epoch 00009: val_loss improved from 0.00100 to 0.00099, saving model to saved_models/weights_best_val_MSE_CNN_Adagrad.hdf5
1712/1712 [==============================] - 21s 12ms/step - loss: 4.3837e-04 - mean_squared_error: 4.3837e-04 - val_loss: 9.9358e-04 - val_mean_squared_error: 9.9358e-04
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.1562e-04 - mean_squared_error: 4.1562e-04Epoch 00010: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 4.1577e-04 - mean_squared_error: 4.1577e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.0411e-04 - mean_squared_error: 4.0411e-04Epoch 00011: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 4.0386e-04 - mean_squared_error: 4.0386e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.0300e-04 - mean_squared_error: 4.0300e-04Epoch 00012: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 4.0285e-04 - mean_squared_error: 4.0285e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.8228e-04 - mean_squared_error: 3.8228e-04Epoch 00013: val_loss improved from 0.00099 to 0.00099, saving model to saved_models/weights_best_val_MSE_CNN_Adagrad.hdf5
1712/1712 [==============================] - 21s 12ms/step - loss: 3.8193e-04 - mean_squared_error: 3.8193e-04 - val_loss: 9.8818e-04 - val_mean_squared_error: 9.8818e-04
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.7666e-04 - mean_squared_error: 3.7666e-04Epoch 00014: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.7587e-04 - mean_squared_error: 3.7587e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.6888e-04 - mean_squared_error: 3.6888e-04Epoch 00015: val_loss improved from 0.00099 to 0.00098, saving model to saved_models/weights_best_val_MSE_CNN_Adagrad.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 3.6886e-04 - mean_squared_error: 3.6886e-04 - val_loss: 9.8247e-04 - val_mean_squared_error: 9.8247e-04
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.6981e-04 - mean_squared_error: 3.6981e-04Epoch 00016: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.7054e-04 - mean_squared_error: 3.7054e-04 - val_loss: 9.8757e-04 - val_mean_squared_error: 9.8757e-04
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.5134e-04 - mean_squared_error: 3.5134e-04Epoch 00017: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.5122e-04 - mean_squared_error: 3.5122e-04 - val_loss: 9.8379e-04 - val_mean_squared_error: 9.8379e-04
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.4641e-04 - mean_squared_error: 3.4641e-04Epoch 00018: val_loss did not improve
1712/1712 [==============================] - 21s 13ms/step - loss: 3.4652e-04 - mean_squared_error: 3.4652e-04 - val_loss: 9.9644e-04 - val_mean_squared_error: 9.9644e-04
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.3802e-04 - mean_squared_error: 3.3802e-04Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 3.3810e-04 - mean_squared_error: 3.3810e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.4064e-04 - mean_squared_error: 3.4064e-04Epoch 00020: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.4027e-04 - mean_squared_error: 3.4027e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.3728e-04 - mean_squared_error: 3.3728e-04Epoch 00021: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.3678e-04 - mean_squared_error: 3.3678e-04 - val_loss: 9.9609e-04 - val_mean_squared_error: 9.9609e-04
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.2653e-04 - mean_squared_error: 3.2653e-04 ETAEpoch 00022: val_loss improved from 0.00098 to 0.00098, saving model to saved_models/weights_best_val_MSE_CNN_Adagrad.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 3.2662e-04 - mean_squared_error: 3.2662e-04 - val_loss: 9.7588e-04 - val_mean_squared_error: 9.7588e-04
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.3121e-04 - mean_squared_error: 3.3121e-04Epoch 00023: val_loss improved from 0.00098 to 0.00097, saving model to saved_models/weights_best_val_MSE_CNN_Adagrad.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 3.3078e-04 - mean_squared_error: 3.3078e-04 - val_loss: 9.7463e-04 - val_mean_squared_error: 9.7463e-04
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.2239e-04 - mean_squared_error: 3.2239e-04Epoch 00024: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.2297e-04 - mean_squared_error: 3.2297e-04 - val_loss: 9.9373e-04 - val_mean_squared_error: 9.9373e-04
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.2584e-04 - mean_squared_error: 3.2584e-04Epoch 00025: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.2539e-04 - mean_squared_error: 3.2539e-04 - val_loss: 9.8290e-04 - val_mean_squared_error: 9.8290e-04
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.2004e-04 - mean_squared_error: 3.2004e-04Epoch 00026: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.2078e-04 - mean_squared_error: 3.2078e-04 - val_loss: 9.8691e-04 - val_mean_squared_error: 9.8691e-04
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.0609e-04 - mean_squared_error: 3.0609e-04Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.0607e-04 - mean_squared_error: 3.0607e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.0801e-04 - mean_squared_error: 3.0801e-04Epoch 00028: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.0895e-04 - mean_squared_error: 3.0895e-04 - val_loss: 9.9016e-04 - val_mean_squared_error: 9.9016e-04
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.1014e-04 - mean_squared_error: 3.1014e-04Epoch 00029: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.0998e-04 - mean_squared_error: 3.0998e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.0408e-04 - mean_squared_error: 3.0408e-04 ETA: 1s - loss: 3.0256e-04 - mean_squared_errorEpoch 00030: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.0401e-04 - mean_squared_error: 3.0401e-04 - val_loss: 9.8371e-04 - val_mean_squared_error: 9.8371e-04
Checking CNN_Adadelta
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.9410e-04 - mean_squared_error: 2.9410e-04Epoch 00001: val_loss improved from inf to 0.00100, saving model to saved_models/weights_best_val_MSE_CNN_Adadelta.hdf5
1712/1712 [==============================] - 26s 15ms/step - loss: 2.9472e-04 - mean_squared_error: 2.9472e-04 - val_loss: 9.9982e-04 - val_mean_squared_error: 9.9982e-04
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.9654e-04 - mean_squared_error: 2.9654e-04Epoch 00002: val_loss improved from 0.00100 to 0.00099, saving model to saved_models/weights_best_val_MSE_CNN_Adadelta.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 2.9588e-04 - mean_squared_error: 2.9588e-04 - val_loss: 9.9468e-04 - val_mean_squared_error: 9.9468e-04
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8947e-04 - mean_squared_error: 2.8947e-04Epoch 00003: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.8888e-04 - mean_squared_error: 2.8888e-04 - val_loss: 9.9534e-04 - val_mean_squared_error: 9.9534e-04
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.9473e-04 - mean_squared_error: 2.9473e-04Epoch 00004: val_loss improved from 0.00099 to 0.00098, saving model to saved_models/weights_best_val_MSE_CNN_Adadelta.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 2.9428e-04 - mean_squared_error: 2.9428e-04 - val_loss: 9.7755e-04 - val_mean_squared_error: 9.7755e-04
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8847e-04 - mean_squared_error: 2.8847e-04Epoch 00005: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.8824e-04 - mean_squared_error: 2.8824e-04 - val_loss: 9.8432e-04 - val_mean_squared_error: 9.8432e-04
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8772e-04 - mean_squared_error: 2.8772e-04Epoch 00006: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.8851e-04 - mean_squared_error: 2.8851e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8473e-04 - mean_squared_error: 2.8473e-04Epoch 00007: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.8567e-04 - mean_squared_error: 2.8567e-04 - val_loss: 9.8597e-04 - val_mean_squared_error: 9.8597e-04
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.9241e-04 - mean_squared_error: 2.9241e-04Epoch 00008: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.9247e-04 - mean_squared_error: 2.9247e-04 - val_loss: 9.8279e-04 - val_mean_squared_error: 9.8279e-04
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.9211e-04 - mean_squared_error: 2.9211e-04Epoch 00009: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.9181e-04 - mean_squared_error: 2.9181e-04 - val_loss: 9.8306e-04 - val_mean_squared_error: 9.8306e-04
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8414e-04 - mean_squared_error: 2.8414e-04Epoch 00010: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.8408e-04 - mean_squared_error: 2.8408e-04 - val_loss: 9.8892e-04 - val_mean_squared_error: 9.8892e-04
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.9225e-04 - mean_squared_error: 2.9225e-04Epoch 00011: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.9243e-04 - mean_squared_error: 2.9243e-04 - val_loss: 9.8424e-04 - val_mean_squared_error: 9.8424e-04
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8308e-04 - mean_squared_error: 2.8308e-04Epoch 00012: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.8315e-04 - mean_squared_error: 2.8315e-04 - val_loss: 9.9820e-04 - val_mean_squared_error: 9.9820e-04
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8442e-04 - mean_squared_error: 2.8442e-04Epoch 00013: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.8550e-04 - mean_squared_error: 2.8550e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8265e-04 - mean_squared_error: 2.8265e-04Epoch 00014: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.8236e-04 - mean_squared_error: 2.8236e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8025e-04 - mean_squared_error: 2.8025e-04Epoch 00015: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.8051e-04 - mean_squared_error: 2.8051e-04 - val_loss: 9.9837e-04 - val_mean_squared_error: 9.9837e-04
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8575e-04 - mean_squared_error: 2.8575e-04Epoch 00016: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.8605e-04 - mean_squared_error: 2.8605e-04 - val_loss: 9.9130e-04 - val_mean_squared_error: 9.9130e-04
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8544e-04 - mean_squared_error: 2.8544e-04Epoch 00017: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.8511e-04 - mean_squared_error: 2.8511e-04 - val_loss: 9.8993e-04 - val_mean_squared_error: 9.8993e-04
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.9370e-04 - mean_squared_error: 2.9370e-04Epoch 00018: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.9382e-04 - mean_squared_error: 2.9382e-04 - val_loss: 9.9304e-04 - val_mean_squared_error: 9.9304e-04
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.7848e-04 - mean_squared_error: 2.7848e-04Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.7813e-04 - mean_squared_error: 2.7813e-04 - val_loss: 9.9176e-04 - val_mean_squared_error: 9.9176e-04
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8360e-04 - mean_squared_error: 2.8360e-04Epoch 00020: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.8333e-04 - mean_squared_error: 2.8333e-04 - val_loss: 9.8902e-04 - val_mean_squared_error: 9.8902e-04
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.7777e-04 - mean_squared_error: 2.7777e-04Epoch 00021: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.7791e-04 - mean_squared_error: 2.7791e-04 - val_loss: 9.9432e-04 - val_mean_squared_error: 9.9432e-04
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8296e-04 - mean_squared_error: 2.8296e-04Epoch 00022: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.8266e-04 - mean_squared_error: 2.8266e-04 - val_loss: 9.8974e-04 - val_mean_squared_error: 9.8974e-04
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.7755e-04 - mean_squared_error: 2.7755e-04Epoch 00023: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 2.7770e-04 - mean_squared_error: 2.7770e-04 - val_loss: 9.8627e-04 - val_mean_squared_error: 9.8627e-04
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.7749e-04 - mean_squared_error: 2.7749e-04Epoch 00024: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.7831e-04 - mean_squared_error: 2.7831e-04 - val_loss: 9.7779e-04 - val_mean_squared_error: 9.7779e-04
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8068e-04 - mean_squared_error: 2.8068e-04Epoch 00025: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.8021e-04 - mean_squared_error: 2.8021e-04 - val_loss: 9.9223e-04 - val_mean_squared_error: 9.9223e-04
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8261e-04 - mean_squared_error: 2.8261e-04Epoch 00026: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.8230e-04 - mean_squared_error: 2.8230e-04 - val_loss: 9.8954e-04 - val_mean_squared_error: 9.8954e-04
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.7448e-04 - mean_squared_error: 2.7448e-04Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.7542e-04 - mean_squared_error: 2.7542e-04 - val_loss: 9.8691e-04 - val_mean_squared_error: 9.8691e-04
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.7873e-04 - mean_squared_error: 2.7873e-04Epoch 00028: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.7900e-04 - mean_squared_error: 2.7900e-04 - val_loss: 9.9087e-04 - val_mean_squared_error: 9.9087e-04
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.7308e-04 - mean_squared_error: 2.7308e-04Epoch 00029: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.7278e-04 - mean_squared_error: 2.7278e-04 - val_loss: 9.9256e-04 - val_mean_squared_error: 9.9256e-04
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.7563e-04 - mean_squared_error: 2.7563e-04Epoch 00030: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.7580e-04 - mean_squared_error: 2.7580e-04 - val_loss: 9.8506e-04 - val_mean_squared_error: 9.8506e-04
Checking CNN_Adam
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.4185e-04 - mean_squared_error: 4.4185e-04Epoch 00001: val_loss improved from inf to 0.00105, saving model to saved_models/weights_best_val_MSE_CNN_Adam.hdf5
1712/1712 [==============================] - 26s 15ms/step - loss: 4.4143e-04 - mean_squared_error: 4.4143e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.8242e-04 - mean_squared_error: 4.8242e-04Epoch 00002: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 4.8225e-04 - mean_squared_error: 4.8225e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.8797e-04 - mean_squared_error: 4.8797e-04Epoch 00003: val_loss improved from 0.00105 to 0.00105, saving model to saved_models/weights_best_val_MSE_CNN_Adam.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 4.8841e-04 - mean_squared_error: 4.8841e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.4841e-04 - mean_squared_error: 4.4841e-04Epoch 00004: val_loss improved from 0.00105 to 0.00104, saving model to saved_models/weights_best_val_MSE_CNN_Adam.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 4.4918e-04 - mean_squared_error: 4.4918e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.2839e-04 - mean_squared_error: 4.2839e-04Epoch 00005: val_loss improved from 0.00104 to 0.00102, saving model to saved_models/weights_best_val_MSE_CNN_Adam.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 4.2840e-04 - mean_squared_error: 4.2840e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.1015e-04 - mean_squared_error: 4.1015e-04Epoch 00006: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 4.1067e-04 - mean_squared_error: 4.1067e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.9491e-04 - mean_squared_error: 3.9491e-04Epoch 00007: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.9506e-04 - mean_squared_error: 3.9506e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.9062e-04 - mean_squared_error: 3.9062e-04Epoch 00008: val_loss improved from 0.00102 to 0.00100, saving model to saved_models/weights_best_val_MSE_CNN_Adam.hdf5
1712/1712 [==============================] - 23s 14ms/step - loss: 3.9185e-04 - mean_squared_error: 3.9185e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.7841e-04 - mean_squared_error: 3.7841e-04Epoch 00009: val_loss improved from 0.00100 to 0.00096, saving model to saved_models/weights_best_val_MSE_CNN_Adam.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 3.7830e-04 - mean_squared_error: 3.7830e-04 - val_loss: 9.6117e-04 - val_mean_squared_error: 9.6117e-04
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.7622e-04 - mean_squared_error: 3.7622e-04Epoch 00010: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 3.7604e-04 - mean_squared_error: 3.7604e-04 - val_loss: 9.9275e-04 - val_mean_squared_error: 9.9275e-04
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.6443e-04 - mean_squared_error: 3.6443e-04Epoch 00011: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 3.6518e-04 - mean_squared_error: 3.6518e-04 - val_loss: 9.9950e-04 - val_mean_squared_error: 9.9950e-04
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.5926e-04 - mean_squared_error: 3.5926e-04Epoch 00012: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 3.5919e-04 - mean_squared_error: 3.5919e-04 - val_loss: 9.8545e-04 - val_mean_squared_error: 9.8545e-04
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.4781e-04 - mean_squared_error: 3.4781e-04Epoch 00013: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.4967e-04 - mean_squared_error: 3.4967e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.4406e-04 - mean_squared_error: 3.4406e-04Epoch 00014: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.4375e-04 - mean_squared_error: 3.4375e-04 - val_loss: 9.9796e-04 - val_mean_squared_error: 9.9796e-04
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.4654e-04 - mean_squared_error: 3.4654e-04Epoch 00015: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 3.4620e-04 - mean_squared_error: 3.4620e-04 - val_loss: 9.9102e-04 - val_mean_squared_error: 9.9102e-04
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.3694e-04 - mean_squared_error: 3.3694e-04Epoch 00016: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.3704e-04 - mean_squared_error: 3.3704e-04 - val_loss: 9.8018e-04 - val_mean_squared_error: 9.8018e-04
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.3282e-04 - mean_squared_error: 3.3282e-04Epoch 00017: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 3.3258e-04 - mean_squared_error: 3.3258e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.3426e-04 - mean_squared_error: 3.3426e-04Epoch 00018: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.3508e-04 - mean_squared_error: 3.3508e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.2704e-04 - mean_squared_error: 3.2704e-04Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.3024e-04 - mean_squared_error: 3.3024e-04 - val_loss: 9.6231e-04 - val_mean_squared_error: 9.6231e-04
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.2960e-04 - mean_squared_error: 3.2960e-04Epoch 00020: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.3024e-04 - mean_squared_error: 3.3024e-04 - val_loss: 9.9624e-04 - val_mean_squared_error: 9.9624e-04
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.3306e-04 - mean_squared_error: 3.3306e-04Epoch 00021: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 3.3328e-04 - mean_squared_error: 3.3328e-04 - val_loss: 9.8320e-04 - val_mean_squared_error: 9.8320e-04
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.1439e-04 - mean_squared_error: 3.1439e-04Epoch 00022: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.1422e-04 - mean_squared_error: 3.1422e-04 - val_loss: 9.6734e-04 - val_mean_squared_error: 9.6734e-04
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.1425e-04 - mean_squared_error: 3.1425e-04Epoch 00023: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.1469e-04 - mean_squared_error: 3.1469e-04 - val_loss: 9.9575e-04 - val_mean_squared_error: 9.9575e-04
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.0172e-04 - mean_squared_error: 3.0172e-04Epoch 00024: val_loss improved from 0.00096 to 0.00095, saving model to saved_models/weights_best_val_MSE_CNN_Adam.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 3.0205e-04 - mean_squared_error: 3.0205e-04 - val_loss: 9.5435e-04 - val_mean_squared_error: 9.5435e-04
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.9781e-04 - mean_squared_error: 2.9781e-04Epoch 00025: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.9765e-04 - mean_squared_error: 2.9765e-04 - val_loss: 9.6498e-04 - val_mean_squared_error: 9.6498e-04
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.8539e-04 - mean_squared_error: 2.8539e-04Epoch 00026: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.8566e-04 - mean_squared_error: 2.8566e-04 - val_loss: 9.6700e-04 - val_mean_squared_error: 9.6700e-04
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.9916e-04 - mean_squared_error: 2.9916e-04Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.9894e-04 - mean_squared_error: 2.9894e-04 - val_loss: 9.6737e-04 - val_mean_squared_error: 9.6737e-04
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.0804e-04 - mean_squared_error: 3.0804e-04Epoch 00028: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 3.0941e-04 - mean_squared_error: 3.0941e-04 - val_loss: 9.6941e-04 - val_mean_squared_error: 9.6941e-04
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.9757e-04 - mean_squared_error: 2.9757e-04Epoch 00029: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.9747e-04 - mean_squared_error: 2.9747e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.0016e-04 - mean_squared_error: 3.0016e-04Epoch 00030: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 3.0068e-04 - mean_squared_error: 3.0068e-04 - val_loss: 9.9178e-04 - val_mean_squared_error: 9.9178e-04
Checking CNN_Adamax
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.0631e-04 - mean_squared_error: 3.0631e-04Epoch 00001: val_loss improved from inf to 0.00095, saving model to saved_models/weights_best_val_MSE_CNN_Adamax.hdf5
1712/1712 [==============================] - 26s 15ms/step - loss: 3.0614e-04 - mean_squared_error: 3.0614e-04 - val_loss: 9.5305e-04 - val_mean_squared_error: 9.5305e-04
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.5600e-04 - mean_squared_error: 2.5600e-04Epoch 00002: val_loss improved from 0.00095 to 0.00094, saving model to saved_models/weights_best_val_MSE_CNN_Adamax.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 2.5612e-04 - mean_squared_error: 2.5612e-04 - val_loss: 9.4424e-04 - val_mean_squared_error: 9.4424e-04
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.3359e-04 - mean_squared_error: 2.3359e-04Epoch 00003: val_loss improved from 0.00094 to 0.00094, saving model to saved_models/weights_best_val_MSE_CNN_Adamax.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 2.3402e-04 - mean_squared_error: 2.3402e-04 - val_loss: 9.3706e-04 - val_mean_squared_error: 9.3706e-04
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.3857e-04 - mean_squared_error: 2.3857e-04Epoch 00004: val_loss improved from 0.00094 to 0.00093, saving model to saved_models/weights_best_val_MSE_CNN_Adamax.hdf5
1712/1712 [==============================] - 23s 14ms/step - loss: 2.3846e-04 - mean_squared_error: 2.3846e-04 - val_loss: 9.3439e-04 - val_mean_squared_error: 9.3439e-04
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.3123e-04 - mean_squared_error: 2.3123e-04Epoch 00005: val_loss improved from 0.00093 to 0.00093, saving model to saved_models/weights_best_val_MSE_CNN_Adamax.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 2.3190e-04 - mean_squared_error: 2.3190e-04 - val_loss: 9.3070e-04 - val_mean_squared_error: 9.3070e-04
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.2567e-04 - mean_squared_error: 2.2567e-04Epoch 00006: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.2543e-04 - mean_squared_error: 2.2543e-04 - val_loss: 9.4266e-04 - val_mean_squared_error: 9.4266e-04
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.2311e-04 - mean_squared_error: 2.2311e-04Epoch 00007: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.2345e-04 - mean_squared_error: 2.2345e-04 - val_loss: 9.5591e-04 - val_mean_squared_error: 9.5591e-04
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.3136e-04 - mean_squared_error: 2.3136e-04Epoch 00008: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.3084e-04 - mean_squared_error: 2.3084e-04 - val_loss: 9.4900e-04 - val_mean_squared_error: 9.4900e-04
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.2660e-04 - mean_squared_error: 2.2660e-04Epoch 00009: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.2696e-04 - mean_squared_error: 2.2696e-04 - val_loss: 9.5238e-04 - val_mean_squared_error: 9.5238e-04
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1543e-04 - mean_squared_error: 2.1543e-04Epoch 00010: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.1532e-04 - mean_squared_error: 2.1532e-04 - val_loss: 9.4847e-04 - val_mean_squared_error: 9.4847e-04
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.2045e-04 - mean_squared_error: 2.2045e-04 ETA: 2s - loss: 2.2068e-04 - mean_squEpoch 00011: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.1978e-04 - mean_squared_error: 2.1978e-04 - val_loss: 9.3218e-04 - val_mean_squared_error: 9.3218e-04
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1994e-04 - mean_squared_error: 2.1994e-04Epoch 00012: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.1975e-04 - mean_squared_error: 2.1975e-04 - val_loss: 9.4336e-04 - val_mean_squared_error: 9.4336e-04
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.2237e-04 - mean_squared_error: 2.2237e-04Epoch 00013: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.2286e-04 - mean_squared_error: 2.2286e-04 - val_loss: 9.3217e-04 - val_mean_squared_error: 9.3217e-04
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1188e-04 - mean_squared_error: 2.1188e-04Epoch 00014: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.1150e-04 - mean_squared_error: 2.1150e-04 - val_loss: 9.4353e-04 - val_mean_squared_error: 9.4353e-04
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.2103e-04 - mean_squared_error: 2.2103e-04Epoch 00015: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.2112e-04 - mean_squared_error: 2.2112e-04 - val_loss: 9.7119e-04 - val_mean_squared_error: 9.7119e-04
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1984e-04 - mean_squared_error: 2.1984e-04Epoch 00016: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.1944e-04 - mean_squared_error: 2.1944e-04 - val_loss: 9.4753e-04 - val_mean_squared_error: 9.4753e-04
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1114e-04 - mean_squared_error: 2.1114e-04Epoch 00017: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.1088e-04 - mean_squared_error: 2.1088e-04 - val_loss: 9.4270e-04 - val_mean_squared_error: 9.4270e-04
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1506e-04 - mean_squared_error: 2.1506e-04Epoch 00018: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.1488e-04 - mean_squared_error: 2.1488e-04 - val_loss: 9.6797e-04 - val_mean_squared_error: 9.6797e-04
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1414e-04 - mean_squared_error: 2.1414e-04Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.1382e-04 - mean_squared_error: 2.1382e-04 - val_loss: 9.5986e-04 - val_mean_squared_error: 9.5986e-04
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1163e-04 - mean_squared_error: 2.1163e-04Epoch 00020: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.1204e-04 - mean_squared_error: 2.1204e-04 - val_loss: 9.5949e-04 - val_mean_squared_error: 9.5949e-04
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1342e-04 - mean_squared_error: 2.1342e-04Epoch 00021: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.1330e-04 - mean_squared_error: 2.1330e-04 - val_loss: 9.5917e-04 - val_mean_squared_error: 9.5917e-04
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1308e-04 - mean_squared_error: 2.1308e-04Epoch 00022: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.1249e-04 - mean_squared_error: 2.1249e-04 - val_loss: 9.3743e-04 - val_mean_squared_error: 9.3743e-04
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.0436e-04 - mean_squared_error: 2.0436e-04Epoch 00023: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.0393e-04 - mean_squared_error: 2.0393e-04 - val_loss: 9.6778e-04 - val_mean_squared_error: 9.6778e-04
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.0388e-04 - mean_squared_error: 2.0388e-04Epoch 00024: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.0383e-04 - mean_squared_error: 2.0383e-04 - val_loss: 9.6135e-04 - val_mean_squared_error: 9.6135e-04
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.0298e-04 - mean_squared_error: 2.0298e-04Epoch 00025: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.0281e-04 - mean_squared_error: 2.0281e-04 - val_loss: 9.4444e-04 - val_mean_squared_error: 9.4444e-04
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1113e-04 - mean_squared_error: 2.1113e-04Epoch 00026: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.1197e-04 - mean_squared_error: 2.1197e-04 - val_loss: 9.6913e-04 - val_mean_squared_error: 9.6913e-04
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.0808e-04 - mean_squared_error: 2.0808e-04Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.0781e-04 - mean_squared_error: 2.0781e-04 - val_loss: 9.6294e-04 - val_mean_squared_error: 9.6294e-04
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.0424e-04 - mean_squared_error: 2.0424e-04Epoch 00028: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.0383e-04 - mean_squared_error: 2.0383e-04 - val_loss: 9.8934e-04 - val_mean_squared_error: 9.8934e-04
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.0910e-04 - mean_squared_error: 2.0910e-04Epoch 00029: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.0869e-04 - mean_squared_error: 2.0869e-04 - val_loss: 9.4171e-04 - val_mean_squared_error: 9.4171e-04
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1199e-04 - mean_squared_error: 2.1199e-04Epoch 00030: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 2.1204e-04 - mean_squared_error: 2.1204e-04 - val_loss: 9.6073e-04 - val_mean_squared_error: 9.6073e-04
Checking CNN_Nadam
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.8278e-04 - mean_squared_error: 3.8278e-04Epoch 00001: val_loss improved from inf to 0.00112, saving model to saved_models/weights_best_val_MSE_CNN_Nadam.hdf5
1712/1712 [==============================] - 27s 16ms/step - loss: 3.8313e-04 - mean_squared_error: 3.8313e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 5.3417e-04 - mean_squared_error: 5.3417e-04Epoch 00002: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 5.3403e-04 - mean_squared_error: 5.3403e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 5.1467e-04 - mean_squared_error: 5.1467e-04Epoch 00003: val_loss improved from 0.00112 to 0.00109, saving model to saved_models/weights_best_val_MSE_CNN_Nadam.hdf5
1712/1712 [==============================] - 23s 14ms/step - loss: 5.1399e-04 - mean_squared_error: 5.1399e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.3980e-04 - mean_squared_error: 4.3980e-04Epoch 00004: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 4.4150e-04 - mean_squared_error: 4.4150e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.3532e-04 - mean_squared_error: 4.3532e-04Epoch 00005: val_loss improved from 0.00109 to 0.00104, saving model to saved_models/weights_best_val_MSE_CNN_Nadam.hdf5
1712/1712 [==============================] - 23s 14ms/step - loss: 4.3523e-04 - mean_squared_error: 4.3523e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.1926e-04 - mean_squared_error: 4.1926e-04Epoch 00006: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 4.2098e-04 - mean_squared_error: 4.2098e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.6790e-04 - mean_squared_error: 4.6790e-04Epoch 00007: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 4.6684e-04 - mean_squared_error: 4.6684e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.6746e-04 - mean_squared_error: 4.6746e-04Epoch 00008: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 4.6772e-04 - mean_squared_error: 4.6772e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.1693e-04 - mean_squared_error: 4.1693e-04Epoch 00009: val_loss improved from 0.00104 to 0.00104, saving model to saved_models/weights_best_val_MSE_CNN_Nadam.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 4.1653e-04 - mean_squared_error: 4.1653e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.9251e-04 - mean_squared_error: 3.9251e-04Epoch 00010: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 3.9268e-04 - mean_squared_error: 3.9268e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.9103e-04 - mean_squared_error: 3.9103e-04Epoch 00011: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 3.9108e-04 - mean_squared_error: 3.9108e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.2303e-04 - mean_squared_error: 4.2303e-04Epoch 00012: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 4.2278e-04 - mean_squared_error: 4.2278e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.3795e-04 - mean_squared_error: 4.3795e-04Epoch 00013: val_loss improved from 0.00104 to 0.00104, saving model to saved_models/weights_best_val_MSE_CNN_Nadam.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 4.3754e-04 - mean_squared_error: 4.3754e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.2685e-04 - mean_squared_error: 4.2685e-04Epoch 00014: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 4.2650e-04 - mean_squared_error: 4.2650e-04 - val_loss: 0.0010 - val_mean_squared_error: 0.0010
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.2265e-04 - mean_squared_error: 4.2265e-04Epoch 00015: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 4.2264e-04 - mean_squared_error: 4.2264e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - mean_squared_error: 0.0010        Epoch 00016: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0010 - mean_squared_error: 0.0010 - val_loss: 0.0027 - val_mean_squared_error: 0.0027
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0046 - mean_squared_error: 0.0046Epoch 00017: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0046 - mean_squared_error: 0.0046 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - mean_squared_error: 0.0044Epoch 00018: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0044 - mean_squared_error: 0.0044 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - mean_squared_error: 0.0044Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0044 - mean_squared_error: 0.0044 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - mean_squared_error: 0.0044Epoch 00020: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0044 - mean_squared_error: 0.0044 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - mean_squared_error: 0.0044Epoch 00021: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0044 - mean_squared_error: 0.0044 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - mean_squared_error: 0.0044Epoch 00022: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0044 - mean_squared_error: 0.0044 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - mean_squared_error: 0.0044Epoch 00023: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0044 - mean_squared_error: 0.0044 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - mean_squared_error: 0.0044Epoch 00024: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0044 - mean_squared_error: 0.0044 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - mean_squared_error: 0.0044Epoch 00025: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0044 - mean_squared_error: 0.0044 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - mean_squared_error: 0.0044Epoch 00026: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0044 - mean_squared_error: 0.0044 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - mean_squared_error: 0.0044Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0044 - mean_squared_error: 0.0044 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - mean_squared_error: 0.0044Epoch 00028: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0044 - mean_squared_error: 0.0044 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - mean_squared_error: 0.0044Epoch 00029: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0044 - mean_squared_error: 0.0044 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - mean_squared_error: 0.0044Epoch 00030: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0044 - mean_squared_error: 0.0044 - val_loss: 0.0044 - val_mean_squared_error: 0.0044
In [116]:
# Plot the validation MSEs of all the models trained above with different optimizers
for name in opt_names:
    plt.plot(history[name].history['val_mean_squared_error'])
plt.title('Validation MSEs with Different Optimizers')
plt.ylabel('Validation MSE')
plt.xlabel('Epoch')
plt.ylim(0.0008, 0.00300)
plt.subplots_adjust(left=0.0, right=2.0, bottom=0.0, top=2.0)
plt.legend(opt_names, loc='center left', bbox_to_anchor=(1, 0.5))
plt.show()

Step 7: Visualize the Loss and Test Predictions

(IMPLEMENTATION) Answer a few questions and visualize the loss

Question 1: Outline the steps you took to get to your final neural network architecture and your reasoning at each step.

Answer:The CNN architecture chosen to have 4 convolution and maxpooling layers for high level feature extraction, and 2 dense layers for the classifier. Initially I used 3 conv layers but adding 1 extra conv and fully connected layer helped to get slightly more accuracy. Regarding the hyperparameters, used the adam as the optimizer and dropout rate for regularizations of 0.2 in the fully connected layers to improve generalization/reduce overfitting.The number of epochs also settled from intial testing of 20, 30. Out of this 30 but I increased epochs number from 30 to 5 to give more time for loss to converge and accuracy to increase slightly.

Question 2: Defend your choice of optimizer. Which optimizers did you test, and how did you determine which worked best?

Answer: I tried all the optimizers provided by Keras for 30 epochs. and ended up selecting the one with the lowest validation MSE.The best results were provided by Adagrad, Adadelta, Adam and Adamax. Out of this, I selected the Adam optimizer for my model as this provided better performace on the validation set.

Use the code cell below to plot the training and validation loss of your neural network. You may find this resource useful.

In [138]:
from keras.optimizers import SGD, RMSprop, Adagrad, Adadelta, Adam, Adamax, Nadam
from keras.callbacks import ModelCheckpoint 

epochs = 50
batch_size = 64

checkpointer = ModelCheckpoint(filepath='weights.final_2.hdf5', 
                               verbose=1, save_best_only=True)

## TODO: Compile the model
model.compile(optimizer='adam', loss='mse', metrics=['accuracy'])

hist_final = model.fit(X_train, y_train, validation_split=0.2,
          epochs=epochs, batch_size=batch_size, callbacks=[checkpointer], verbose=1)


model.save('my_model_final.h5')
Train on 1712 samples, validate on 428 samples
Epoch 1/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0301 - acc: 0.4411Epoch 00001: val_loss improved from inf to 0.00729, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 25s 15ms/step - loss: 0.0296 - acc: 0.4457 - val_loss: 0.0073 - val_acc: 0.6963
Epoch 2/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0087 - acc: 0.5871Epoch 00002: val_loss improved from 0.00729 to 0.00509, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 17s 10ms/step - loss: 0.0087 - acc: 0.5882 - val_loss: 0.0051 - val_acc: 0.6963
Epoch 3/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0067 - acc: 0.6136Epoch 00003: val_loss improved from 0.00509 to 0.00447, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 18s 11ms/step - loss: 0.0067 - acc: 0.6157 - val_loss: 0.0045 - val_acc: 0.6963
Epoch 4/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0062 - acc: 0.6400Epoch 00004: val_loss improved from 0.00447 to 0.00411, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 20s 12ms/step - loss: 0.0062 - acc: 0.6425 - val_loss: 0.0041 - val_acc: 0.6963
Epoch 5/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0055 - acc: 0.6562Epoch 00005: val_loss improved from 0.00411 to 0.00382, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0055 - acc: 0.6560 - val_loss: 0.0038 - val_acc: 0.6963
Epoch 6/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0052 - acc: 0.6538Epoch 00006: val_loss improved from 0.00382 to 0.00368, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 19s 11ms/step - loss: 0.0052 - acc: 0.6560 - val_loss: 0.0037 - val_acc: 0.6963
Epoch 7/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0047 - acc: 0.6532Epoch 00007: val_loss improved from 0.00368 to 0.00336, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 19s 11ms/step - loss: 0.0047 - acc: 0.6577 - val_loss: 0.0034 - val_acc: 0.6916
Epoch 8/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0042 - acc: 0.6851Epoch 00008: val_loss improved from 0.00336 to 0.00277, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 18s 11ms/step - loss: 0.0043 - acc: 0.6799 - val_loss: 0.0028 - val_acc: 0.7033
Epoch 9/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0038 - acc: 0.6971Epoch 00009: val_loss improved from 0.00277 to 0.00257, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 18s 11ms/step - loss: 0.0038 - acc: 0.6957 - val_loss: 0.0026 - val_acc: 0.7056
Epoch 10/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0034 - acc: 0.6905Epoch 00010: val_loss improved from 0.00257 to 0.00238, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 18s 11ms/step - loss: 0.0034 - acc: 0.6916 - val_loss: 0.0024 - val_acc: 0.7056
Epoch 11/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0030 - acc: 0.7001Epoch 00011: val_loss improved from 0.00238 to 0.00220, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 18s 11ms/step - loss: 0.0030 - acc: 0.7004 - val_loss: 0.0022 - val_acc: 0.7196
Epoch 12/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0028 - acc: 0.6995Epoch 00012: val_loss improved from 0.00220 to 0.00193, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 18s 11ms/step - loss: 0.0028 - acc: 0.6986 - val_loss: 0.0019 - val_acc: 0.7220
Epoch 13/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0026 - acc: 0.6923Epoch 00013: val_loss improved from 0.00193 to 0.00180, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 20s 12ms/step - loss: 0.0026 - acc: 0.6922 - val_loss: 0.0018 - val_acc: 0.7266
Epoch 14/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0025 - acc: 0.7163Epoch 00014: val_loss improved from 0.00180 to 0.00178, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0025 - acc: 0.7144 - val_loss: 0.0018 - val_acc: 0.7243
Epoch 15/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0025 - acc: 0.7218Epoch 00015: val_loss improved from 0.00178 to 0.00168, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0025 - acc: 0.7249 - val_loss: 0.0017 - val_acc: 0.7336
Epoch 16/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0024 - acc: 0.7212Epoch 00016: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0024 - acc: 0.7220 - val_loss: 0.0017 - val_acc: 0.7290
Epoch 17/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0023 - acc: 0.7338Epoch 00017: val_loss improved from 0.00168 to 0.00157, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0023 - acc: 0.7313 - val_loss: 0.0016 - val_acc: 0.7336
Epoch 18/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0021 - acc: 0.7320Epoch 00018: val_loss improved from 0.00157 to 0.00148, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0021 - acc: 0.7354 - val_loss: 0.0015 - val_acc: 0.7313
Epoch 19/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0020 - acc: 0.7368Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 25s 14ms/step - loss: 0.0020 - acc: 0.7354 - val_loss: 0.0020 - val_acc: 0.7430
Epoch 20/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0020 - acc: 0.7386Epoch 00020: val_loss improved from 0.00148 to 0.00145, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 26s 15ms/step - loss: 0.0020 - acc: 0.7331 - val_loss: 0.0015 - val_acc: 0.7523
Epoch 21/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0019 - acc: 0.7464Epoch 00021: val_loss improved from 0.00145 to 0.00141, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 25s 15ms/step - loss: 0.0019 - acc: 0.7459 - val_loss: 0.0014 - val_acc: 0.7407
Epoch 22/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0019 - acc: 0.7494Epoch 00022: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0019 - acc: 0.7518 - val_loss: 0.0017 - val_acc: 0.7453
Epoch 23/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7446Epoch 00023: val_loss did not improve
1712/1712 [==============================] - 20s 12ms/step - loss: 0.0018 - acc: 0.7453 - val_loss: 0.0015 - val_acc: 0.7617
Epoch 24/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7566Epoch 00024: val_loss improved from 0.00141 to 0.00135, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0017 - acc: 0.7553 - val_loss: 0.0013 - val_acc: 0.7593
Epoch 25/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7626Epoch 00025: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0017 - acc: 0.7640 - val_loss: 0.0014 - val_acc: 0.7547
Epoch 26/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7572Epoch 00026: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0017 - acc: 0.7576 - val_loss: 0.0015 - val_acc: 0.7664
Epoch 27/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7554Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0017 - acc: 0.7576 - val_loss: 0.0015 - val_acc: 0.7664
Epoch 28/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7680Epoch 00028: val_loss improved from 0.00135 to 0.00131, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0016 - acc: 0.7669 - val_loss: 0.0013 - val_acc: 0.7664
Epoch 29/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7710Epoch 00029: val_loss improved from 0.00131 to 0.00128, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0015 - acc: 0.7739 - val_loss: 0.0013 - val_acc: 0.7687
Epoch 30/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7680Epoch 00030: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0016 - acc: 0.7704 - val_loss: 0.0015 - val_acc: 0.7921
Epoch 31/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7770Epoch 00031: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0015 - acc: 0.7775 - val_loss: 0.0013 - val_acc: 0.7850
Epoch 32/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7812Epoch 00032: val_loss improved from 0.00128 to 0.00126, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 25s 15ms/step - loss: 0.0015 - acc: 0.7810 - val_loss: 0.0013 - val_acc: 0.7734
Epoch 33/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7788Epoch 00033: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0015 - acc: 0.7792 - val_loss: 0.0013 - val_acc: 0.7874
Epoch 34/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7692Epoch 00034: val_loss improved from 0.00126 to 0.00121, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0014 - acc: 0.7704 - val_loss: 0.0012 - val_acc: 0.7780
Epoch 35/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7873Epoch 00035: val_loss improved from 0.00121 to 0.00118, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0014 - acc: 0.7874 - val_loss: 0.0012 - val_acc: 0.7897
Epoch 36/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7800Epoch 00036: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0014 - acc: 0.7815 - val_loss: 0.0012 - val_acc: 0.7850
Epoch 37/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7999Epoch 00037: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0014 - acc: 0.8002 - val_loss: 0.0013 - val_acc: 0.7921
Epoch 38/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7819Epoch 00038: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0013 - acc: 0.7798 - val_loss: 0.0013 - val_acc: 0.7874
Epoch 39/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7915Epoch 00039: val_loss did not improve
1712/1712 [==============================] - 21s 13ms/step - loss: 0.0013 - acc: 0.7921 - val_loss: 0.0012 - val_acc: 0.8014
Epoch 40/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7933Epoch 00040: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0012 - acc: 0.7932 - val_loss: 0.0013 - val_acc: 0.7757
Epoch 41/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7861Epoch 00041: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0012 - acc: 0.7886 - val_loss: 0.0012 - val_acc: 0.7850
Epoch 42/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7909Epoch 00042: val_loss improved from 0.00118 to 0.00118, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 21s 12ms/step - loss: 0.0013 - acc: 0.7921 - val_loss: 0.0012 - val_acc: 0.7897
Epoch 43/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7909Epoch 00043: val_loss improved from 0.00118 to 0.00117, saving model to weights.final_2.hdf5
1712/1712 [==============================] - 21s 13ms/step - loss: 0.0012 - acc: 0.7926 - val_loss: 0.0012 - val_acc: 0.7921
Epoch 44/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7957Epoch 00044: val_loss did not improve
1712/1712 [==============================] - 21s 13ms/step - loss: 0.0012 - acc: 0.7956 - val_loss: 0.0012 - val_acc: 0.7897
Epoch 45/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.8041Epoch 00045: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0011 - acc: 0.8055 - val_loss: 0.0012 - val_acc: 0.7921
Epoch 46/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.8029Epoch 00046: val_loss did not improve
1712/1712 [==============================] - 20s 12ms/step - loss: 0.0011 - acc: 0.8020 - val_loss: 0.0013 - val_acc: 0.7780
Epoch 47/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.8083Epoch 00047: val_loss did not improve
1712/1712 [==============================] - 18s 11ms/step - loss: 0.0012 - acc: 0.8107 - val_loss: 0.0012 - val_acc: 0.8084
Epoch 48/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.8029Epoch 00048: val_loss did not improve
1712/1712 [==============================] - 18s 11ms/step - loss: 0.0012 - acc: 0.8055 - val_loss: 0.0012 - val_acc: 0.7850
Epoch 49/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.8113Epoch 00049: val_loss did not improve
1712/1712 [==============================] - 18s 11ms/step - loss: 0.0011 - acc: 0.8119 - val_loss: 0.0013 - val_acc: 0.7897
Epoch 50/50
1664/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.8173Epoch 00050: val_loss did not improve
1712/1712 [==============================] - 18s 11ms/step - loss: 0.0011 - acc: 0.8154 - val_loss: 0.0012 - val_acc: 0.7780
In [139]:
# Visualize the training and validation loss of the neural network# Visual 
plt.plot(range(epochs), hist_final.history[
         'val_loss'], 'g-', label='Val Loss')
plt.plot(range(epochs), hist_final.history[
         'loss'], 'g--', label='Train Loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.show()

Question 3: Do you notice any evidence of overfitting or underfitting in the above plot? If so, what steps have you taken to improve your model? Note that slight overfitting or underfitting will not hurt your chances of a successful submission, as long as you have attempted some solutions towards improving your model (such as regularization, dropout, increased/decreased number of layers, etc).

Answer:Not much overfitting can be observed in the above plot, since validation loss and training loss seems to converge and validation is not lower than training loss. Using maxpooling and dropout helped to reduce the overfitting effect.

Visualize a Subset of the Test Predictions

Execute the code cell below to visualize your model's predicted keypoints on a subset of the testing images.

In [153]:
model.load_weights('weights.final_2.hdf5')
y_test = model.predict(X_test)
fig = plt.figure(figsize=(20,20))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
for i in range(9):
    ax = fig.add_subplot(3, 3, i + 1, xticks=[], yticks=[])
    plot_data(X_test[i], y_test[i], ax)

Step 8: Complete the pipeline

With the work you did in Sections 1 and 2 of this notebook, along with your freshly trained facial keypoint detector, you can now complete the full pipeline. That is given a color image containing a person or persons you can now

  • Detect the faces in this image automatically using OpenCV
  • Predict the facial keypoints in each face detected in the image
  • Paint predicted keypoints on each face detected

In this Subsection you will do just this!

(IMPLEMENTATION) Facial Keypoints Detector

Use the OpenCV face detection functionality you built in previous Sections to expand the functionality of your keypoints detector to color images with arbitrary size. Your function should perform the following steps

  1. Accept a color image.
  2. Convert the image to grayscale.
  3. Detect and crop the face contained in the image.
  4. Locate the facial keypoints in the cropped image.
  5. Overlay the facial keypoints in the original (color, uncropped) image.

Note: step 4 can be the trickiest because remember your convolutional network is only trained to detect facial keypoints in $96 \times 96$ grayscale images where each pixel was normalized to lie in the interval $[0,1]$, and remember that each facial keypoint was normalized during training to the interval $[-1,1]$. This means - practically speaking - to paint detected keypoints onto a test face you need to perform this same pre-processing to your candidate face - that is after detecting it you should resize it to $96 \times 96$ and normalize its values before feeding it into your facial keypoint detector. To be shown correctly on the original image the output keypoints from your detector then need to be shifted and re-normalized from the interval $[-1,1]$ to the width and height of your detected face.

When complete you should be able to produce example images like the one below

In [143]:
def face_detector(image_path):
    
    # Load in color image for face detection
    image = cv2.imread('images/obamas4.jpg')

    # Convert the image to RGB colorspace
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

    # Convert the image from RGB to GRAY colorspace
    gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

    # Extract the pre-trained face detector from an xml file
    face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

    # Detect the faces in image
    faces = face_cascade.detectMultiScale(gray, 2, 6)
   
    # Print the number of faces detected in the image
    print('Number of faces detected:', len(faces))

    # Make a copy of the orginal image to draw face detections on
    image_with_detections = np.copy(image)

    # Get the bounding box for each detected face
    for (x,y,w,h) in faces:
        # Add a red bounding box to the detections image
        cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    return faces, image_with_detections
In [123]:
image_path = 'images/obamas4.jpg'
detected_faces, image_with_detections = face_detector(image_path)

plt.imshow(image_with_detections)
Number of faces detected: 2
Out[123]:
<matplotlib.image.AxesImage at 0x5c05f6d8>
In [145]:
### TODO: Use the face detection code we saw in Section 1 with your trained conv-net
def face_keypoints_detector(image, model_path):
    
    # Convert the image to GRAY colorspace
    gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

    #detect faces
    face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')
    faces = face_cascade.detectMultiScale(gray, 2, 6)
    
    num_face_keypoints = []
    
    # Loop through faces
    for i, (x,y,w,h) in enumerate(faces):
        
        cv2.rectangle(image, (x,y), (x+w,y+h),(255,0,0), 3)
        
        # Crop Faces
        face = gray[y:y+h, x:x+w]

        # Scale face to 96x96
        scaled_face = cv2.resize(face, (96,96), 0, 0, interpolation=cv2.INTER_AREA)

        # Normalize image to be between 0 and 1
        normalized_image = scaled_face / 255

        # Format image to be the correct shape for the model
        normalized_image = np.expand_dims(normalized_image, axis = 0)
        normalized_image = np.expand_dims(normalized_image, axis = -1)

        # Use model to predict keypoints on image
        #model = load_model(model_path)
        keypoints = model.predict(normalized_image)[0]

        # Adjust keypoints to coordinates of original image
        keypoints[0::2] = keypoints[0::2] * w/2 + w/2 + x
        keypoints[1::2] = keypoints[1::2] * h/2 + h/2 + y
        num_face_keypoints.append(keypoints)
        
        # Paint keypoints on image
        for point in range(15):
            cv2.circle(image, (keypoints[2*point], keypoints[2*point + 1]), 2, (0, 255, 0), -1)
        
    return image, faces, num_face_keypoints
In [155]:
model_path = 'my_model_final.h5'

# Load in color image for face detection# Load in 
image = cv2.imread('images/obamas4.jpg')

# Convert the image to RGB colorspace
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

img, faces, keypoints = face_keypoints_detector(image_rgb, model_path)
fig = plt.figure(figsize=(20,20))
ax = fig.add_subplot(111)
ax.set_xticks([])
ax.set_yticks([])
ax.imshow(img)
Out[155]:
<matplotlib.image.AxesImage at 0xce4d320>

(Optional) Further Directions - add a filter using facial keypoints to your laptop camera

Now you can add facial keypoint detection to your laptop camera - as illustrated in the gif below.

The next Python cell contains the basic laptop video camera function used in the previous optional video exercises. Combine it with the functionality you developed for keypoint detection and marking in the previous exercise and you should be good to go!

In [157]:
import cv2
import time 
from keras.models import load_model
def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # keep video stream open
    while rval:
        
        frame, _, _ = face_keypoints_detector(frame, model_path)
        # plot image from camera with detections marked
        cv2.imshow("face detection activated", frame)
        
        # exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        # Exit this loop on escape:
        if(key == 27) :
            # Destroy windows 
            cv2.destroyAllWindows()
            break;
        
        # read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()  
In [158]:
# Run your keypoint face painter
laptop_camera_go()

(Optional) Further Directions - add a filter using facial keypoints

Using your freshly minted facial keypoint detector pipeline you can now do things like add fun filters to a person's face automatically. In this optional exercise you can play around with adding sunglasses automatically to each individual's face in an image as shown in a demonstration image below.

To produce this effect an image of a pair of sunglasses shown in the Python cell below.

In [159]:
# Load in sunglasses image - note the usage of the special option
# cv2.IMREAD_UNCHANGED, this option is used because the sunglasses 
# image has a 4th channel that allows us to control how transparent each pixel in the image is
sunglasses = cv2.imread("images/sunglasses_4.png", cv2.IMREAD_UNCHANGED)

# Plot the image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.imshow(sunglasses)
ax1.axis('off');

This image is placed over each individual's face using the detected eye points to determine the location of the sunglasses, and eyebrow points to determine the size that the sunglasses should be for each person (one could also use the nose point to determine this).

Notice that this image actually has 4 channels, not just 3.

In [160]:
# Print out the shape of the sunglasses image
print ('The sunglasses image has shape: ' + str(np.shape(sunglasses)))
The sunglasses image has shape: (1123, 3064, 4)

It has the usual red, blue, and green channels any color image has, with the 4th channel representing the transparency level of each pixel in the image. Here's how the transparency channel works: the lower the value, the more transparent the pixel will become. The lower bound (completely transparent) is zero here, so any pixels set to 0 will not be seen.

This is how we can place this image of sunglasses on someone's face and still see the area around of their face where the sunglasses lie - because these pixels in the sunglasses image have been made completely transparent.

Lets check out the alpha channel of our sunglasses image in the next Python cell. Note because many of the pixels near the boundary are transparent we'll need to explicitly print out non-zero values if we want to see them.

In [161]:
# Print out the sunglasses transparency (alpha) channel
alpha_channel = sunglasses[:,:,3]
print ('the alpha channel here looks like')
print (alpha_channel)

# Just to double check that there are indeed non-zero values
# Let's find and print out every value greater than zero
values = np.where(alpha_channel != 0)
print ('\n the non-zero values of the alpha channel look like')
print (values)
the alpha channel here looks like
[[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 ..., 
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]

 the non-zero values of the alpha channel look like
(array([  17,   17,   17, ..., 1109, 1109, 1109], dtype=int64), array([ 687,  688,  689, ..., 2376, 2377, 2378], dtype=int64))

This means that when we place this sunglasses image on top of another image, we can use the transparency channel as a filter to tell us which pixels to overlay on a new image (only the non-transparent ones with values greater than zero).

One last thing: it's helpful to understand which keypoint belongs to the eyes, mouth, etc. So, in the image below, we also display the index of each facial keypoint directly on the image so that you can tell which keypoints are for the eyes, eyebrows, etc.

With this information, you're well on your way to completing this filtering task! See if you can place the sunglasses automatically on the individuals in the image loaded in / shown in the next Python cell.

In [162]:
# Load in color image for face detection
image = cv2.imread('images/obamas4.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)


# Plot the image
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Original Image')
ax1.imshow(image)
Out[162]:
<matplotlib.image.AxesImage at 0xd1c3198>
In [163]:
## (Optional) TODO: Use the face detection code we saw in Section 1 with your trained conv-net to put
## sunglasses on the individuals in our test image

def overlay_sunglasses(keypoints, image):
    '''
        Adds sunglasses to a persons face.
    '''
    sunglasses = cv2.imread("images/sunglasses_4.png", cv2.IMREAD_UNCHANGED)
    for i in range(len(keypoints)):
        # resize sunglasses image to match eyebrow keypoints
        glasses_width = 1.1*(keypoints[i][14] - keypoints[i][18])
        scale_factor = glasses_width/sunglasses.shape[1]
        sg = cv2.resize(sunglasses,None, fx=scale_factor, fy = scale_factor, interpolation=cv2.INTER_AREA)
        width = sg.shape[1]
        height = sg.shape[0]
        
        # top left corner of sunglasses: x coordinate = average x coordinate of eyes - width/2
        x1 = int((keypoints[i][2] + keypoints[i][0])/2 - width/2)
        x2 = x1 + width

        # top left corner of sunglasses: y coordinate = average y coordinate of eyes - height/2
        y1 = int((keypoints[i][3] + keypoints[i][1])/2 - height/3)
        y2 = y1 + height
        # Create an alpha mask based on the transparency values
        alpha_sun = np.expand_dims(sg[:, :, 3]/255.0, axis=-1)
        alpha_face = 1.0 - alpha_sun
        
        # Take a weighted sum of the image and the sunglasses using the alpha values and (1- alpha)
        image[y1:y2, x1:x2] = (alpha_sun * sg[:, :, :3] + alpha_face * image[y1:y2, x1:x2])
    
    return image
In [164]:
image_path = 'images/obamas4.jpg'
model_path = 'my_model_final.h5'

test_image = cv2.imread(image_path)

# Convert the image to RGB colorspace
test_image_rgb = cv2.cvtColor(test_image, cv2.COLOR_BGR2RGB)

image, faces, keypoints = face_keypoints_detector(test_image_rgb, model_path)
# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))
img = overlay_sunglasses(keypoints, image)

# Plot the image
fig = plt.figure(figsize = (20,20))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Original Image')
ax1.imshow(img)
Number of faces detected: 2
Out[164]:
<matplotlib.image.AxesImage at 0xd1f8940>

(Optional) Further Directions - add a filter using facial keypoints to your laptop camera

Now you can add the sunglasses filter to your laptop camera - as illustrated in the gif below.

The next Python cell contains the basic laptop video camera function used in the previous optional video exercises. Combine it with the functionality you developed for adding sunglasses to someone's face in the previous optional exercise and you should be good to go!

In [167]:
import cv2
import time 
from keras.models import load_model
import numpy as np

# Load facial landmark detector model
model = load_model('my_model_final.h5')

def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep video stream open
    while rval:
        
        _, _, keypoints = face_keypoints_detector(frame, model_path)
        if len(keypoints) > 0:
            frame = overlay_sunglasses(keypoints, frame)
            
        # Plot image from camera with detections marked
        cv2.imshow("face detection activated", frame)
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        # Exit this loop on escape:
        if(key == 27) :
            # Destroy windows 
            cv2.destroyAllWindows()
            break;
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
        
In [168]:
# Run sunglasses painter
laptop_camera_go()